package org.efssc
def GetPom(appname){
    def jarname = sh returnStdout: true, script: "cd ${appname}/target;ls *.jar"
    env.jarName = jarname - "\n"
    def pom = readMavenPom file: 'pod.xml'
    env.pomVersion = "${pom.version}"
    env.pomArtifact = "${pom.artifactId}"
    env.pomPackaging = "${pom.packaging}"
    env.pomGroupId = "${pom.groupId}"
    println("${pomGroupId}-${pomArtifact}-${pomVersion}-${pomPackaging}")
    return ["${pomGroupId}","${pomArtifact}","${pomVersion}","${pomPackaging}"]
}

def MavenUpload(appname,nexusserver){
//    sh  """
//        cd ${appname}/target/
//        mvn deploy:deploy-file -Dmaven.test.skip=true  \
//                                -Dfile=${jarName} -DgroupId=${pomGroupId} \
//                                -DartifactId=${pomArtifact} -Dversion=${pomVersion}  \
//                                -Dpackaging=${pomPackaging} -DrepositoryId=galaxy-nexus-releases \
//                                -Durl=${nexusserver}
//                                """     //账号密码会从setting文件中获取
    sh """
        cd ${appname}
        mvn clean deploy -gs devops/settings.xml -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
"""
}

def main(uploadType,appname,nexueserver){
    def jarapp = ["galaxy-boot","galaxy-framework","galaxy-cloud"]
    result = jarapp.any{it == "${appname}"}
    if ("${result}" == true ) {
        GetPom("${appname}")
        if ("$uploadType" == "maven"){
            MavenUpload("${appname}","${nexueserver}")
        } else if ("$uploadType" == "nexus"){
            println("接口还没有开发")
        }
    }
}